#ifndef STATUS_H_
#define STATUS_H_

#ifndef HTTP_SERVUNAVAIL
#define	HTTP_SERVUNAVAIL	503
#endif

#define MAX_RECENT_RESULTS	50
#define IDLE_TIME	10

struct pattern {
	TAILQ_ENTRY(pattern) next;

	char *pattern_host;
	char *pattern_uri;
};

TAILQ_HEAD(patternq, pattern);

/* structure where we keep track of patterns */
struct pattern_obj {
	const char *location;
	struct patternq head;
	int count;
	struct timeval tv_load;

};

#define PATTERN_REFRESH_SECONDS	3600	/* once an hour - is that too often */

#define STATE_EXPIRATION_TIME	500

struct site {
	SPLAY_ENTRY(site) (node);
	TAILQ_ENTRY(site) (next);
	
	char *url;
	struct site *parent;

	int flags;
#define ANALYSIS_COMPLETE	0x01

	TAILQ_HEAD(siteq, site) (children);

	enum DANGER_TYPES {
		HARMLESS = 0,
		UNKNOWN = 1,
		DANGEROUS = 2
	} danger;

	char *html_data;	/* delivered data */
	size_t html_size;

	struct timeval tv_change;

	struct event ev_timeout;
	struct event ev_complete;
};

struct stats {
	int num_requests;
	int num_harmless;
	int num_unknown;
	int num_dangerous;
};
static const char *css_style =
    ".statistics h1 {\n"
    "  padding: 3px;"
    "  font-size: small;\n"
    "  background-color: #F2FDF3;\n"
    "  border: 1px solid;\n"
    "}\n"
    ".statistics {\n"
    "  width: 80%;\n"
    "  margin: 10px;\n"
    "  background-color: #f2fdf3;\n"
    "  font-family: Verdana, Arial;\n"
    "  font-size: 0.8em;\n"
    "  padding: 1em;\n"
    "}\n"
    ".analysis {\n"
    "  font-family: Verdana, Arial;\n"
    "  font-size: small;\n"
    "}\n"
    ".harmless { color: green }\n"
    ".unknown { color: orange }\n"
    ".dangerous { color: red }\n"
    ".banner {\n"
    "  background: #F2FDF3;\n"
    "  font-family: Verdana, Arial;\n"
    "  border: 2px solid;\n"
    "}\n"
    ".banner h1 {\n"
	"  margin-left: 1em;\n"
	"  margin-top: 0em;\n"
    "  margin-bottom: 0.5em;\n"
    "}\n"
    ".banner ul {\n"
    "  margin-bottom: 0em;\n"
    "}\n"
    ".banner li {\n"
    "  display: inline;\n"
    "}\n"
    "\n"
    ".footer {\n"
    "  font-family: Verdana, Arial;\n"
    "  font-size: 0.7em;\n"
    "  text-align: center;\n"
    "}\n";
void amproxy_handle_request(struct evhttp_request *request, void *arg);

void status_init(const char *whitelist, const char *blackness);
struct site *site_new(const char *url, const char *parent_url);
void site_free(struct site *site);
struct site *site_find(const char *url);

void site_cache_data(struct site *site, const struct evhttp_request *req);

void status_good_patterns(struct evbuffer *data);
void status_bad_patterns(struct evbuffer *data);

const char *danger_to_text(enum DANGER_TYPES danger);


#endif /* STATUS_H_ */
